package com.youlai.boot.modules.exhibition.controller;

import com.youlai.boot.modules.exhibition.service.ExhibitionBrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.modules.exhibition.model.ExhibitionBrandForm;
import com.youlai.boot.modules.exhibition.model.ExhibitionBrandQuery;
import com.youlai.boot.modules.exhibition.model.ExhibitionBrandVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 展会品牌关联前端控制层
 *
 * @author maoyu
 * @since 2025-04-17 14:53
 */
@Tag(name = "展会品牌关联接口")
@RestController
@RequestMapping("/api/v1/exhibitionBrands")
@RequiredArgsConstructor
public class ExhibitionBrandController  {

    private final ExhibitionBrandService exhibitionBrandService;

    @Operation(summary = "展会品牌关联分页列表")
    @GetMapping("/page")
//    @PreAuthorize("@ss.hasPerm('modules:exhibitionBrand:query')")
    public PageResult<ExhibitionBrandVO> getExhibitionBrandPage(ExhibitionBrandQuery queryParams ) {
        IPage<ExhibitionBrandVO> result = exhibitionBrandService.getExhibitionBrandPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增展会品牌关联")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('m:brand:add')")
    public Result<Void> saveExhibitionBrand(@RequestBody @Valid ExhibitionBrandForm formData ) {
        boolean result = exhibitionBrandService.saveExhibitionBrand(formData);
        if (result) {
            return Result.judge(result);
        }else {
            return Result.failed("品牌已添加");
        }

    }

    @Operation(summary = "获取展会品牌关联表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('modules:exhibitionBrand:edit')")
    public Result<ExhibitionBrandForm> getExhibitionBrandForm(
        @Parameter(description = "展会品牌关联ID") @PathVariable Long id
    ) {
        ExhibitionBrandForm formData = exhibitionBrandService.getExhibitionBrandFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改展会品牌关联")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('modules:exhibitionBrand:edit')")
    public Result<Void> updateExhibitionBrand(
            @Parameter(description = "展会品牌关联ID") @PathVariable Long id,
            @RequestBody @Validated ExhibitionBrandForm formData
    ) {
        boolean result = exhibitionBrandService.updateExhibitionBrand(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除展会品牌关联")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('m:brand:delete')")
    public Result<Void> deleteExhibitionBrands(
        @Parameter(description = "展会品牌关联ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = exhibitionBrandService.deleteExhibitionBrands(ids);
        return Result.judge(result);
    }
}
